home *** CD-ROM | disk | FTP | other *** search
- Path: sunsite.doc.ic.ac.uk!demon!ittpub.nl
- From: wil@ittpub.nl (Wil Evers)
- Newsgroups: comp.lang.c++
- Subject: Re: How to ... declare a virtual static function in a class ?
- Date: Mon, 08 Jan 1996 10:35:29 GMT
- Distribution: world
- Message-ID: <821097329.18975@ittpub.nl>
- References: <30EFAC88.13DF@worldcom.ch>
- NNTP-Posting-Host: ittpub.nl
- X-NNTP-Posting-Host: ittpub.nl
-
- In article <30EFAC88.13DF@worldcom.ch> ean-Pierre Schnyder
- <jschnyde@worldcom.ch>Jean-Pierre Schnyder <jschnyde@worldcom.ch> writes:
-
- > Hi,
- >
- > I guess this is not possible. Any idea on the rationale about this
- > limitation ? Thanks, Jean-Pierre
- > --
-
- About half a year ago, there was an interesting discussion about this on
- comp.std.c++. Basically, a static virtual function call would resolve to
- an overloaded version in a derived class (if defined) when called through
- a pointer or reference to an object `myObject->staticVirtual()' and
- statically resolved when called by explicit qualification
- `MyClass::staticVirtual()'. Like an ordinary static member function, it
- would not have a `this' pointer, so it cannot directly access the object
- on which it was called, even when called through an object
- pointer/reference.
-
- Some arguments against it were (I'm sure there were more, but these are
- the ones I remember):
-
- 1. Since a static member function doesn't have a `this' it seems
- counterintuitive to allow dynamic resolution.
-
- 2. (Bjarne Stroustrup in his book on the Design an Evolution of C++:) the
- proponents of static virtual member functions typically have only one
- application in mind: run-time type information. The language already has
- another mechanism to support this.
-
- 3. Static virtual member functions can easily be simulated by having a
- pair of functions instead of just one:
-
- class Base {
- public :
- static void staticFn();
- virtual void dynamicFn() const
- { return staticFn(); }
- };
-
- class Derived : public Base {
- public :
- static void staticFn();
- virtual void dynamicFn() const
- { return dynamicFn(); }
- };
-
- (Here, dynamicFn() calls a particular version of staticFn() depending on
- the dynamic type of the object it was called for. But note that
- dynamicFn() *can* access the object for which it was called, which is more
- than a static virtual would be able to do, so the simulation is not
- perfect.).
-
- 4. Problems in defining what a pointer to a static virtual member function
- should do. Should it keep its dynamic resolution property, when we don't
- know it advance if it will be used in a static or dynamic context?
-
- The discussion became very confusing when people started asking for static
- virtual data members or even plain virtual data members.
-
- One of the proponents of static virtual member functions, Don Organ
- (donorgan@ix.netcom.com) had the courage to actually submit a proposal to
- the ANSI committee. The proposal came rather late, and I'm not sure if it
- has actuallly been included in the C++ standardization process.
-
- - Wil
-